package com.wsl.sale.aop;

import com.wsl.sale.aop.annotation.Action;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @Author:wangshuliang
 * @Description: 注解式拦截
 * @Date:Created in 8:06 2019/5/9
 * @Modified by:
 */
@Aspect
@Component
public class AnnotationAspect {
    @Pointcut("@annotation(com.wsl.sale.aop.annotation.Action)")
    public void annotationPointCut() {
    }

    @After("annotationPointCut()")
    public void after(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        Action action =method.getAnnotation(Action.class);
        System.out.println(action.name());

    }


}
